From 4a30bcd01ecda73b3475f645ad49338b27c3e378 Mon Sep 17 00:00:00 2001 From: Nicolas Koch Date: Sat, 12 Sep 2015 13:27:01 +0200 Subject: [PATCH] Various small changes to cargo_test and friends. - Reworked CargoTestError to contain Vec - Remove #[allow(trivial_casts)] - Coding style fixes --- src/cargo/ops/cargo_test.rs | 8 ++++---- src/cargo/util/errors.rs | 37 +++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index 6370f5c02..8b5ca97a5 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -27,7 +27,7 @@ pub fn run_tests(manifest_path: &Path, // If we have an error and want to fail fast, return if errors.len() > 0 && !options.no_fail_fast { - return Ok(Some(CargoTestError::from(&errors[..]))) + return Ok(Some(CargoTestError::new(errors))) } // If a specific test was requested or we're not running any tests at all, @@ -35,7 +35,7 @@ pub fn run_tests(manifest_path: &Path, if let ops::CompileFilter::Only { .. } = options.compile_opts.filter { match errors.len() { 0 => return Ok(None), - _ => return Ok(Some(CargoTestError::from(&errors[..]))) + _ => return Ok(Some(CargoTestError::new(errors))) } } @@ -43,7 +43,7 @@ pub fn run_tests(manifest_path: &Path, if errors.len() == 0 { Ok(None) } else { - Ok(Some(CargoTestError::from(&errors[..]))) + Ok(Some(CargoTestError::new(errors))) } } @@ -56,7 +56,7 @@ pub fn run_benches(manifest_path: &Path, let errors = try!(run_unit_tests(options, &args, &compilation)); match errors.len() { 0 => Ok(None), - _ => Ok(Some(CargoTestError::from(&errors[..]))), + _ => Ok(Some(CargoTestError::new(errors))), } } diff --git a/src/cargo/util/errors.rs b/src/cargo/util/errors.rs index 622e09c1e..1d53d6fc8 100644 --- a/src/cargo/util/errors.rs +++ b/src/cargo/util/errors.rs @@ -55,7 +55,6 @@ impl<'a, T, F> ChainError for F where F: FnOnce() -> CargoResult { } impl ChainError for Result { - #[allow(trivial_casts)] fn chain_error(self, callback: C) -> CargoResult where E2: CargoError, C: FnOnce() -> E2 { self.map_err(move |err| { @@ -114,7 +113,6 @@ pub struct ProcessError { impl Error for ProcessError { fn description(&self) -> &str { &self.desc } - #[allow(trivial_casts)] fn cause(&self) -> Option<&Error> { self.cause.as_ref().map(|s| s as &Error) } @@ -138,7 +136,24 @@ impl fmt::Debug for ProcessError { pub struct CargoTestError { pub desc: String, pub exit: Option, - cause: Option, + pub causes: Vec, +} + +impl CargoTestError { + #[allow(deprecated)] // connect => join in 1.3 + pub fn new(errors: Vec) -> Self { + if errors.len() == 0 { + panic!("Cannot create CargoTestError from empty Vec") + } + let desc = errors.iter().map(|error| error.desc.clone()) + .collect::>() + .connect("\n"); + CargoTestError { + desc: desc, + exit: errors[0].exit, + causes: errors, + } + } } impl fmt::Display for CargoTestError { @@ -155,22 +170,8 @@ impl fmt::Debug for CargoTestError { impl Error for CargoTestError { fn description(&self) -> &str { &self.desc } - #[allow(trivial_casts)] fn cause(&self) -> Option<&Error> { - self.cause.as_ref().map(|s| s as &Error) - } -} - -#[allow(deprecated)] // connect => join in 1.3 -impl<'a> From<&'a [ProcessError]> for CargoTestError { - fn from(errors: &[ProcessError]) -> Self { - if errors.len() == 0 { panic!("Cannot create CargoTestError from empty Vec") } - let desc = errors.iter().map(|error| error.desc.clone()).collect::>().connect("\n"); - CargoTestError { - desc: desc, - exit: errors[0].exit, - cause: None, - } + self.causes.get(0).map(|s| s as &Error) } } -- 2.30.2